import configs,time,sys,os
from AliyunDNS import ChangeDns
import GUI

# 打印基本信息
info = ChangeDns.DomainInfo()
# 初始化域名解析记录
Record = ChangeDns.ListRecord()
# 开启死循环
while True:
    # 清除前面的输出
    os.system('cls' if os.name == 'nt' else 'clear')
    # 打印GUI
    GUI.GUI()
    try:
        select = input('Please input option：')
    except:
        print('Please check your input......')
        time.sleep(3)
    if(select == '0'):
        print()
        print('\nProgram exit！Thank you for using......\n')
        # 停顿5秒后退出程序
        time.sleep(5)
        sys.exit()
    if(select == '1'):
        # 清除前面的输出
        os.system('cls' if os.name == 'nt' else 'clear')
        # 将值传递给GUI模块绘制图形
        GUI.RecordList(Record)
        input('\nEnter exit......\n')
    if(select == '2'):
        addrecordinfo = GUI.AddRecords()
        if(addrecordinfo):
            ChangeDns.AddRecord(addrecordinfo[0],addrecordinfo[1])
            Record = ChangeDns.ListRecord()
    if(select == '3'):
        # 清除前面的输出
        os.system('cls' if os.name == 'nt' else 'clear')
        # 将值传递给GUI模块绘制图形
        GUI.RecordList(Record)
        print()
        try:
            select = int(input("Please enter the number you want to delete:"))
        except:
            print('Please check your input......')
            time.sleep(3)
        if(Record[select-1].record_id == configs.RecordId):
            print('\nThis record cannot be deleted....')
            time.sleep(3)
            continue
        ChangeDns.DeleteRecord(Record[select-1].record_id)
        Record = ChangeDns.ListRecord()
    if(select == '4'):
        # 清除前面的输出
        os.system('cls' if os.name == 'nt' else 'clear')
        # 将值传递给GUI模块绘制图形
        GUI.RecordList(Record)
        print()
        try:
            id = int(input("Please enter the number you want to modify:"))
        except:
            print('Please check your input......')
            time.sleep(3)
        if (Record[id - 1].record_id == configs.RecordId):
            print('\nThis record cannot be modified....')
            time.sleep(3)
            continue
        try:
            RecordName = input("Please enter the RecordName you want to modify:")
            IP = input("Please enter the IP you want to modify:")

        except:
            print('Please check your input......')
            time.sleep(3)

        ChangeDns.ModifyRecord(Record[id-1].record_id,RecordName,IP)
        Record = ChangeDns.ListRecord()
    if(select == '5'):
        # 清除前面的输出
        os.system('cls' if os.name == 'nt' else 'clear')
        GUI.DomainInfo(info)
        try:
            select = input('input enter to next:')
        except:
            pass



